from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

driver = webdriver.Firefox()
driver.maximize_window()
url = 'https://www.baidu.com/'
driver.get(url)

# 设置cookie
# BDUSS 百度登录成功的cookie
driver.add_cookie({
    'name': 'BDUSS',
    'value': 'pwZH5YZXEwSG1YLUZIZTBEUm1WZERjeEwwUXBVOWZwOGZicFJDYTh-cERDRWhuRVFBQUFBJCQAAAAAAAAAAAEAAACHQjM~a2FybLPJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEN7IGdDeyBnNm'
})
# cookie设置后，必须刷新才会生效
driver.refresh()

# 获取所有的cookie
# cookies = driver.get_cookies()
# # print('cookies：', cookies)
# # 遍历列表，获取每一个cookie
# for item in cookies:
#     print(item['name'])

# 获取指定的cookie
print('BDUSS:', driver.get_cookie('BDUSS'))


sleep(3)
driver.quit()